package  
{
	import org.flixel.FlxSprite;
	import org.flixel.FlxState;
	import org.flixel.FlxText;
	import org.flixel.FlxG;
	
	public class MainMenuState extends FlxState
	{
		[Embed(source = '..//assets//images//menubackground.png')]
		private var MenuBackground:Class;
		
		private var currentMenuChoice : int = 0;
		private var menuChoices : Array = new Array("New Game", "Continue");
		private var menuActions : Array = new Array(onNewGame, onContinue);
		private var menuTexts : Array = new Array(2);
		
		public function MainMenuState() 
		{
			super();
		}
		
		override public function create():void 
		{			
			var menubg:FlxSprite = new FlxSprite(0, 0, MenuBackground);
			add(menubg);
			
			for (var i : int = 0; i < menuChoices.length; i++)
			{
				var logo : FlxText = new FlxText(FlxG.width / 4, 200 + i * 50, FlxG.width / 2,
					menuChoices[i]);
				logo.setFormat(null, 30, 0xff0000, 'center');
				add(logo);
				menuTexts[i] = logo;
			}
			super.create();
		}
		
		override public function update():void 
		{
			if (FlxG.keys.justPressed("ENTER"))
			{
				menuActions[currentMenuChoice]();
			}
			else if (FlxG.keys.justPressed("DOWN"))
			{
				currentMenuChoice = (currentMenuChoice+menuActions.length-1) % menuActions.length;
			}
			else if (FlxG.keys.justPressed("UP"))
			{
				currentMenuChoice = (currentMenuChoice+1) % menuActions.length;
			}
			for (var i : int = 0; i < menuChoices.length; i++)
			{
				menuTexts[i].color = 0x000000;
				if (i == currentMenuChoice)		
					menuTexts[i].color = 0x00ff00;		
			}
			
			super.update();
		}
		
		private function onNewGame() : void
		{
			FlxG.switchState(new MainState());
		}
		
		private function onContinue() : void
		{
			FlxG.switchState(new MainState());
		}
		
	}
}